package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/ABCServlet")
public class ABCServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public ABCServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	
	public void destroy() {
		// TODO Auto-generated method stub
	}


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 设置请求编码格式
	    request.setCharacterEncoding("UTF-8");
	    // 设置响应编码格式
	    response.setContentType("text/html;charset=UTF-8");
	    
	    response.setHeader("Content-Type", "text/html;charset=UTF-8");
	    response.setHeader("Content-Length", "1024");   
	    response.setHeader("Content-Encoding", "gzip");                    
	    response.setHeader("Content-Language", "zh-CN");                   
	    response.setHeader("Transfer-Encoding", "chunked");                 
	    response.setHeader("Location", "http://www.baidu.com");            
	    response.setHeader("Refresh", "5");                                 
	    response.setHeader("Set-Cookie", "name=abc");                      
	    response.setHeader("Expires", "Thu, 01 Dec 2022 16:00:00 GMT");    
	    response.setHeader("Cache-Control", "no-cache");                    
	    response.setHeader("Pragma", "no-cache");                           
	    response.setHeader("Connection", "keep-alive");                    
	    response.setHeader("Date", new Date(0).toString());            
	    response.setHeader("Server", "Apache"); 
	    
	    // 获取响应输出流
	    PrintWriter writer = response.getWriter();
	    // 生成HTML代码
	    writer.append("<!DOCTYPE html>")
	            .append("<html>")
	            .append("<head>")
	            .append("<title>HTTP响应</title>")
	            .append("</head>")
	            .append("<body>")
	            .append("<h1>HTTP响应</h1>")
	            .append("</body>")
	            .append("</html>");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
